--香火療烟
local xianghuoliaoyan = fk.CreateSkill {
    name = "mcdh_xianghuoliaoyan",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

xianghuoliaoyan:addEffect(fk.AfterCardsMove,{
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 then
            for _, move in ipairs(data) do
                if move.from == player and move.moveReason == fk.ReasonDiscard then
                    for _, info in ipairs(move.moveInfo) do
                        if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                            return true
                        end
                    end
                end
            end
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local tar = room:askToChoosePlayers(player, {
            targets = room:getOtherPlayers(player),
            min_num = 1,
            max_num = 1,
            prompt = "#xianghuoliaoyan",
            skill_name = self.name,
            cancelable = true
          })
        if #tar >0 then
            self.cost_data = tar
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local tar = self.cost_data[1]
        if player:getHandcardNum() == tar:getHandcardNum() then
            room:recover({
                who = tar,
                num = 1,
                recoverBy = player,
                skillName = self.name,
            })
        else
            if not tar:isNude() then
                room:askForDiscard(tar, 1, 1, true, self.name, false, ".", "#xianghuoliaoyan-discard")
            end
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_xianghuoliaoyan"] = "香火療烟",
    [":mcdh_xianghuoliaoyan"] = "每回合限一次，当你的牌因弃置而失去后，你可以选择一名其他角色，若其手牌数等于你，其回复1点体力，否则其弃置一张牌。",
    ["#xianghuoliaoyan"] = "香火療烟：选择一名其他角色，若其手牌数等于你，其回复1点体力，否则其弃置一张牌。",
    ["#xianghuoliaoyan-discard"] = "香火療烟：弃置一张牌",
}

return xianghuoliaoyan